package com.situ.mall.admin.config;
//配置类
//个人springmvc的配置

import com.situ.mall.admin.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//创建配置类的对象
@Configuration
public class MyWebMVCConfig implements WebMvcConfigurer {
//Spring new的
    @Value("${file.path}")
    private String filePath;

    @Value("${file.location}")
    private String fileLocation;

//    添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
//                拦截
                .addPathPatterns("/**")
//                忽略
                .excludePathPatterns("/login",filePath+"**","/css/**","/captcha","/js/**","/lib/**","/images/**");

    }
//    添加一个资源处理器
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        外部资源的映射
        registry.addResourceHandler(filePath+"**")
                .addResourceLocations("file:"+fileLocation);
    }
}
